 <style lang="less" scoped>
.bar-item {
  padding: 4px;
  .left-ratio {
    width: 50px;
    height: 50px;
    float: left;
  }
  .right-content {
    position: relative;
    margin-left: 60px;
    height: 50px;
    .shopType {
      padding-left: 10px;
      color: #fff;
      font-weight: 500;
      font-size: 16px;
      line-height: 25px;
      border: none;
      border-radius: 0px;
      background: rgba(32, 6, 56, 0.4);
    }
    .count {
      padding-left: 10px;
      font-size: 14px;
      color: rgb(176, 194, 249);
      line-height: 30px;
      border: none;
      border-radius: 0px;
      background: rgba(0, 11, 255, 0.0980392);
      .alarm-count {
        color: rgb(234, 108, 109);
        font-weight: 600;
        font-size: 18px;
      }
      .shop-count {
        color: #6fc399;
        font-weight: 600;
        font-size: 16px;
        margin-right: 20px;
      }
    }
  }
}
</style>

<template>
  <div>
    <div v-for="(item, index) in dataList"
         :key="index"
         class="bar-item">
      <div class="left-ratio">
        <i-circle :percent="item.ratio"
                  size="50">
          <div style="font-size:18px;color:#fff;">{{item.ratio}}%</div>
        </i-circle>
      </div>
      <div class="right-content">
        <div class="shopType">{{item.shopType}}</div>
        <div class="count">
          总数：
          <span class="shop-count">{{item.shop_count}}</span> 告警数：
          <span class="alarm-count">{{item.alarm_count}}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getShopPlace } from '@/libs/smoketool'
export default {
  props: {
    dataSource: {
      type: Array,
      default: function() {
        return [
          {
            shopType: '企业',
            shop_count: 152,
            alarm_count: 12,
            ratio: 15
          },
          {
            shopType: '企业',
            shop_count: 152,
            alarm_count: 12,
            ratio: 15
          },
          {
            shopType: '企业',
            shop_count: 152,
            alarm_count: 12,
            ratio: 15
          }
        ]
      }
    }
  },
  data() {
    return {
      dataList: []
    }
  },
  watch: {
    dataSource(curVal, oldVal) {
      let tempArr = []
      curVal.forEach(element => {
        tempArr.push({
          shopType: getShopPlace(element.i),
          shop_count: element.shop_count,
          alarm_count: element.alarm_count,
          ratio:
            element.shop_count > 0
              ? parseInt((element.alarm_count / element.shop_count) * 100)
              : 0
        })
      })
      this.dataList = tempArr
    }
  },
  mounted() {},
  methods: {
    initEchats() {}
  }
}
</script>
